package com.hqq.persistence_tier.data_mapper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Data-Mapper 模式
 * The below example demonstrates basic CRUD operations: Create, Read, Update, and Delete.
 * DataMapper模式将内存中的对象和数据库进行分离。它的职责是在二者之间传输对象，并且使这些对象相互独立
 * 使用DataMapper模式内存对象无需知道数据库的存在,他们不需要SQL接口代码当然也就不知道数据库的表信息
 * Created by heqianqian on 2017/8/14.
 */
public class App {

    private static final Logger LOGGER = LoggerFactory.getLogger(App.class);

    public static void main(String[] args) {
        StudentDataMapper mapper = new StudentDataMapperImpl();

        Student student = new Student(1, "heqianqian", 'A');

        /*insert*/
        mapper.insert(student);
        LOGGER.info("App Main: {} is inserted!", student);

        /*update*/
        student.setName("hqq");
        mapper.update(student);
        LOGGER.info("App Main: {} is updated!", student);

        /*delete*/
        LOGGER.info("App Main: {} is going to be deleted!", student);
        mapper.delete(student);
    }
}
